package com.xiongjie.health;

import io.vertx.core.AbstractVerticle;
import io.vertx.ext.healthchecks.HealthCheckHandler;
import io.vertx.ext.healthchecks.HealthChecks;
import io.vertx.ext.healthchecks.Status;
import io.vertx.ext.web.Router;

public class HealthVertxChecks extends AbstractVerticle {

    @Override
    public void start() {
        HealthCheckHandler healthCheckHandler2 = HealthCheckHandler.createWithHealthChecks(HealthChecks.create(vertx));
        healthCheckHandler2.register("my-procedure-name", 2000,future -> {
            System.out.println("开始进行health check");
            //如果成功则直接返回，否则执行下面语句
            future.complete(Status.OK());
            //失败
            future.complete(Status.KO());
        });

        Router router = Router.router(vertx);
        router.get("/health").handler(healthCheckHandler2);

        vertx.createHttpServer()
                .requestHandler(router)
                .listen(8080);
    }
}
